﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using secondhand.L3object;
using System.Data;
using secondhand.L1database;
using System.IO;

namespace secondhand.L2busslogic
{
    public class goodsBL
    {


        public static goodsOBList Getgoosmo(string goods_name)//获取模糊名称清单
        {

            string commandtext = "select * from goods where goods_name like '%" + goods_name.ToString().Trim() + "%'and master_check= '" + "审核通过" + "'";
            goodsOBList tempList = null;
            tempList = new goodsOBList();
            DataSet ds = null;
            ds = goodsDB.GetItem(commandtext);
            if (ds == null)
            {
                return tempList;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return tempList;
            }

            int count = ds.Tables[0].Rows.Count;
            for (int i = 0; i < count; i++)
            {
                goodsOB myword = new goodsOB();

                myword.goods_ID = ds.Tables[0].Rows[i][0].ToString().Trim();
                myword.goods_name = ds.Tables[0].Rows[i][1].ToString().Trim();
                myword.goods_type = ds.Tables[0].Rows[i][2].ToString().Trim();
                myword.goods_price = ds.Tables[0].Rows[i][3].ToString().Trim();
                myword.goods_describe = ds.Tables[0].Rows[i][4].ToString().Trim();
                myword.goods_picture = ds.Tables[0].Rows[i][5].ToString().Trim();
                myword.sale_time = ds.Tables[0].Rows[i][6].ToString().Trim();
                myword.saler_name = ds.Tables[0].Rows[i][7].ToString().Trim();
                myword.master_check = ds.Tables[0].Rows[i][8].ToString().Trim();


                tempList.Insert(i, myword);
            }
            return tempList;
        }
        public static goodsOBList Getgotypesmo(string goods_type)//获取模糊类型清单
        {

            string commandtext = "select * from goods where goods_type like '%" + goods_type.ToString().Trim() + "%'and master_check= '" + "审核通过" + "'";
            goodsOBList tempList = null;
            tempList = new goodsOBList();
            DataSet ds = null;
            ds = goodsDB.GetItem(commandtext);
            if (ds == null)
            {
                return tempList;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return tempList;
            }

            int count = ds.Tables[0].Rows.Count;
            for (int i = 0; i < count; i++)
            {
                goodsOB myword = new goodsOB();

                myword.goods_ID = ds.Tables[0].Rows[i][0].ToString().Trim();
                myword.goods_name = ds.Tables[0].Rows[i][1].ToString().Trim();
                myword.goods_type = ds.Tables[0].Rows[i][2].ToString().Trim();
                myword.goods_price = ds.Tables[0].Rows[i][3].ToString().Trim();
                myword.goods_describe = ds.Tables[0].Rows[i][4].ToString().Trim();
                myword.goods_picture = ds.Tables[0].Rows[i][5].ToString().Trim();
                myword.sale_time = ds.Tables[0].Rows[i][6].ToString().Trim();
                myword.saler_name = ds.Tables[0].Rows[i][7].ToString().Trim();
                myword.master_check = ds.Tables[0].Rows[i][8].ToString().Trim();


                tempList.Insert(i, myword);
            }
            return tempList;
        }
        public static goodsOBList Getsalersmo(string saler_name)//获取模糊出售者清单
        {

            string commandtext = "select * from goods where saler_name  like '%" + saler_name.ToString().Trim() + "%'and master_check= '" + "审核通过" + "'";
            goodsOBList tempList = null;
            tempList = new goodsOBList();
            DataSet ds = null;
            ds = goodsDB.GetItem(commandtext);
            if (ds == null)
            {
                return tempList;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return tempList;
            }

            int count = ds.Tables[0].Rows.Count;
            for (int i = 0; i < count; i++)
            {
                goodsOB myword = new goodsOB();

                myword.goods_ID = ds.Tables[0].Rows[i][0].ToString().Trim();
                myword.goods_name = ds.Tables[0].Rows[i][1].ToString().Trim();
                myword.goods_type = ds.Tables[0].Rows[i][2].ToString().Trim();
                myword.goods_price = ds.Tables[0].Rows[i][3].ToString().Trim();
                myword.goods_describe = ds.Tables[0].Rows[i][4].ToString().Trim();
                myword.goods_picture = ds.Tables[0].Rows[i][5].ToString().Trim();
                myword.sale_time = ds.Tables[0].Rows[i][6].ToString().Trim();
                myword.saler_name = ds.Tables[0].Rows[i][7].ToString().Trim();
                myword.master_check = ds.Tables[0].Rows[i][8].ToString().Trim();


                tempList.Insert(i, myword);
            }
            return tempList;
        }
        public static goodsOBList Getgoprice(string goods_price) // 价格查询
        {

            string commandtext = "select * from goods where goods_price = '" + goods_price.ToString().Trim() + "'and master_check= '" + "审核通过" + "'";
            goodsOBList tempList = null;
            tempList = new goodsOBList();
            DataSet ds = null;
            ds = goodsDB.GetItem(commandtext);
            if (ds == null)
            {
                return tempList;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return tempList;
            }

            int count = ds.Tables[0].Rows.Count;
            for (int i = 0; i < count; i++)
            {
                goodsOB myword = new goodsOB();

                myword.goods_ID = ds.Tables[0].Rows[i][0].ToString().Trim();
                myword.goods_name = ds.Tables[0].Rows[i][1].ToString().Trim();
                myword.goods_type = ds.Tables[0].Rows[i][2].ToString().Trim();
                myword.goods_price = ds.Tables[0].Rows[i][3].ToString().Trim();
                myword.goods_describe = ds.Tables[0].Rows[i][4].ToString().Trim();
                myword.goods_picture = ds.Tables[0].Rows[i][5].ToString().Trim();
                myword.sale_time = ds.Tables[0].Rows[i][6].ToString().Trim();
                myword.saler_name = ds.Tables[0].Rows[i][7].ToString().Trim();
                myword.master_check = ds.Tables[0].Rows[i][8].ToString().Trim();


                tempList.Insert(i, myword);
            }
            return tempList;
        }
        public static goodsOB Getmark()     //获取数据库中的大单条数据
        {
            string commandtext = "select * from goods ";
            goodsOB myword = new goodsOB();       //数据库对象
            myword.goods_name = "访问数据库不成功！";
            DataSet ds = null;
            ds = goodsDB.GetItem(commandtext);
            if (ds == null)
            {
                return myword;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return myword;
            }

            int i = 0;


            myword.goods_name = ds.Tables[0].Rows[i][1].ToString().Trim();
            myword.goods_type = ds.Tables[0].Rows[i][2].ToString().Trim();
            myword.goods_price = ds.Tables[0].Rows[i][3].ToString().Trim();
            myword.goods_describe = ds.Tables[0].Rows[i][4].ToString().Trim();
            myword.goods_picture = ds.Tables[0].Rows[i][5].ToString().Trim();
            myword.sale_time = ds.Tables[0].Rows[i][6].ToString().Trim();
            myword.saler_name = ds.Tables[0].Rows[i][7].ToString().Trim();
            myword.master_check = ds.Tables[0].Rows[i][8].ToString().Trim();

            return myword;
        }
        public static goodsOBList GetmarkAll(string nameq)       //获取数据库中的所有记录
        {
            string commandtext = "select * from goods where saler_name='" + nameq.Trim() + "'";
            goodsOBList tempList = null;
            tempList = new goodsOBList();
            DataSet ds = null;
            ds = goodsDB.GetItem(commandtext);
            if (ds == null)
            {
                return tempList;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return tempList;
            }

            int count = ds.Tables[0].Rows.Count;
            for (int i = 0; i < count; i++)
            {
                goodsOB myword = new goodsOB();

                myword.goods_name = ds.Tables[0].Rows[i][1].ToString().Trim();
                myword.goods_type = ds.Tables[0].Rows[i][2].ToString().Trim();
                myword.goods_price = ds.Tables[0].Rows[i][3].ToString().Trim();
                myword.goods_describe = ds.Tables[0].Rows[i][4].ToString().Trim();
                myword.goods_picture = ds.Tables[0].Rows[i][5].ToString().Trim();
                myword.sale_time = ds.Tables[0].Rows[i][6].ToString().Trim();
                myword.saler_name = ds.Tables[0].Rows[i][7].ToString().Trim();
                myword.master_check = ds.Tables[0].Rows[i][8].ToString().Trim();


                tempList.Insert(i, myword);
            }
            return tempList;
        }
        public static goodsOBList GetmarkAll1()       //获取数据库中的所有记录
        {
            string commandtext = "select * from goods ";
            goodsOBList tempList = null;
            tempList = new goodsOBList();
            DataSet ds = null;
            ds = goodsDB.GetItem(commandtext);
            if (ds == null)
            {
                return tempList;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return tempList;
            }

            int count = ds.Tables[0].Rows.Count;
            for (int i = 0; i < count; i++)
            {
                goodsOB myword = new goodsOB();

                myword.goods_name = ds.Tables[0].Rows[i][1].ToString().Trim();
                myword.goods_type = ds.Tables[0].Rows[i][2].ToString().Trim();
                myword.goods_price = ds.Tables[0].Rows[i][3].ToString().Trim();
                myword.goods_describe = ds.Tables[0].Rows[i][4].ToString().Trim();
                myword.goods_picture = ds.Tables[0].Rows[i][5].ToString().Trim();
                myword.sale_time = ds.Tables[0].Rows[i][6].ToString().Trim();
                myword.saler_name = ds.Tables[0].Rows[i][7].ToString().Trim();
                myword.master_check = ds.Tables[0].Rows[i][8].ToString().Trim();


                tempList.Insert(i, myword);
            }
            return tempList;
        }
        public static bool Addfill(goodsOB myword)      //添加纪录
        {
            string ss = "INSERT INTO goods (goods_name,goods_type,goods_price,goods_describe,goods_picture,sale_time,saler_name,master_check)VALUES('";
            ss = ss + myword.goods_name.Trim() + "','";
            ss = ss + myword.goods_type.Trim() + "','";
            ss = ss + myword.goods_price.Trim() + "','";
            ss = ss + myword.goods_describe.Trim() + "','";
            ss = ss + myword.goods_picture.Trim() + "','";
            ss = ss + myword.sale_time.Trim() + "','";
            ss = ss + myword.saler_name.Trim() + "','";
            ss = ss + myword.master_check.Trim() + "')";

            return goodsDB.AddDeleteItem(ss);
        }
        public static goodsOB Getwordsingle2(string goods_name)      //按商品名查找
        {
            string commandtext = "select * from goods where goods_name like '%" + goods_name.Trim() + "%'";
            goodsOB myword = new goodsOB();
            myword.goods_name = "访问数据库不成功！";
            DataSet ds = null;
            ds = goodsDB.GetItem(commandtext);
            if (ds == null)
            {
                return myword;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return myword;
            }

            int i = 0;

            myword.goods_ID = ds.Tables[0].Rows[i][0].ToString().Trim();
            myword.goods_name = ds.Tables[0].Rows[i][1].ToString().Trim();
            myword.goods_type = ds.Tables[0].Rows[i][2].ToString().Trim();
            myword.goods_price = ds.Tables[0].Rows[i][3].ToString().Trim();
            myword.goods_describe = ds.Tables[0].Rows[i][4].ToString().Trim();
            myword.goods_picture = ds.Tables[0].Rows[i][5].ToString().Trim();
            myword.sale_time = ds.Tables[0].Rows[i][6].ToString().Trim();
            myword.saler_name = ds.Tables[0].Rows[i][7].ToString().Trim();
            myword.master_check = ds.Tables[0].Rows[i][8].ToString().Trim();

            return myword;
        }
        public static goodsOB Getwordsingle(string nameq)      //按姓名查找
        {
            string commandtext = "select * from goods where goods_name = '" + nameq.Trim() + "'";
            goodsOB myword = new goodsOB();
            myword.goods_name = "访问数据库不成功！";
            DataSet ds = null;
            ds = goodsDB.GetItem(commandtext);
            if (ds == null)
            {
                return myword;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return myword;
            }

            int i = 0;

            myword.goods_ID = ds.Tables[0].Rows[i][0].ToString().Trim();
            myword.goods_name = ds.Tables[0].Rows[i][1].ToString().Trim();
            myword.goods_type = ds.Tables[0].Rows[i][2].ToString().Trim();
            myword.goods_price = ds.Tables[0].Rows[i][3].ToString().Trim();
            myword.goods_describe = ds.Tables[0].Rows[i][4].ToString().Trim();
            myword.goods_picture = ds.Tables[0].Rows[i][5].ToString().Trim();
            myword.sale_time = ds.Tables[0].Rows[i][6].ToString().Trim();
            myword.saler_name = ds.Tables[0].Rows[i][7].ToString().Trim();
            myword.master_check = ds.Tables[0].Rows[i][8].ToString().Trim();

            return myword;
        }
        public static bool Savemark(goodsOB myword)     //修改记录
        {
            string commandtext = "update goods set  goods_name='";
            commandtext = commandtext + myword.goods_name.Trim() + "', goods_type='";
            commandtext = commandtext + myword.goods_type.Trim() + "',goods_price='";
            commandtext = commandtext + myword.goods_price.Trim() + "',goods_describe='";
            commandtext = commandtext + myword.goods_describe.Trim() + "',goods_picture='";
            commandtext = commandtext + myword.goods_picture.Trim() + "', sale_time='";
            commandtext = commandtext + myword.sale_time.Trim() + "',saler_name='";
            commandtext = commandtext + myword.saler_name.Trim() + "',master_check='";
            commandtext = commandtext + myword.master_check.Trim() + "' where goods_ID=";
            commandtext = commandtext + myword.goods_ID.Trim();
            return goodsDB.AddDeleteItem(commandtext);
        }
        public static bool deleteword(string name)      //删除记录
        {

            string ss = "delete from goods where goods_name='" + name.Trim() + "'";
            return goodsDB.AddDeleteItem(ss);
        }
        public static goodsOB Getwordsingle1(string salerName, string nameq)      //按姓名查找
        {

            string commandtext = "select * from goods where saler_name='" + salerName.Trim() + "'" + "and goods_name='" + nameq.Trim()+"'";
            goodsOB myword = new goodsOB();
            myword.goods_name = "访问数据库不成功！";
            DataSet ds = null;
            ds = goodsDB.GetItem(commandtext);
            if (ds == null)
            {
                return myword;
            }
            if (ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6588" || ds.Tables[0].Rows[0][0].ToString().Trim() == "defaulqwesda6577" || ds.Tables[0].Rows[0][0].ToString().Trim() == "-98685")
            {
                return myword;
            }

            int i = 0;

            myword.goods_ID = ds.Tables[0].Rows[i][0].ToString().Trim();
            myword.goods_name = ds.Tables[0].Rows[i][1].ToString().Trim();
            myword.goods_type = ds.Tables[0].Rows[i][2].ToString().Trim();
            myword.goods_price = ds.Tables[0].Rows[i][3].ToString().Trim();
            myword.goods_describe = ds.Tables[0].Rows[i][4].ToString().Trim();
            myword.goods_picture = ds.Tables[0].Rows[i][5].ToString().Trim();
            myword.sale_time = ds.Tables[0].Rows[i][6].ToString().Trim();
            myword.saler_name = ds.Tables[0].Rows[i][7].ToString().Trim();
            myword.master_check = ds.Tables[0].Rows[i][8].ToString().Trim();

            return myword;
        }
    }
}